package com.ganzi.ganziserver.rabbit.recevie;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ganzi.ganziserver.dao.CollectInformationDao;
import com.ganzi.ganziserver.rabbit.send.SendUtil;
import com.ganzi.ganziserver.service.ReceviceService;
import com.ganzi.ganziserver.utils.Topic;
import com.rabbitmq.client.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
public class RecevieTow {

    private static Logger log = LoggerFactory.getLogger(RecevieTow.class);

    @Autowired
    ReceviceService service;

    @RabbitListener(queues = Topic.RECEVIE_TOW)
    public void process(Message message, Channel channel)throws IOException {
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        try{
            log.info("收到客户端消息："+new String(message.getBody()));
            if(message.getBody().length<=0)return;
            JSONObject info = (JSONObject) JSON.parse(message.getBody());
            if(info != null)service.saveReceviceMessage(info);
        }catch (Exception e){
            log.info("接收到异常："+e.getMessage());
        }
    }
}
